package com.css.zfzx.data.thirdary.jgReconciliation.service.impl;

import com.css.zfzx.data.thirdary.jgReconciliation.repository.JgReconciliationRepository;
import com.css.zfzx.data.thirdary.jgReconciliation.repository.entity.SjtgfJghshYjSjdzbEntity;
import com.css.zfzx.data.thirdary.jgReconciliation.service.ReconciliationService;
import com.css.zfzx.data.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author leon
 * @date 2021/1/18 16:32
 */
@Service
public class ReconciliationServiceImpl implements ReconciliationService {
    @Autowired
    JgReconciliationRepository jgReconciliationRepository;

    @Override
    public void saveReconciliation(SjtgfJghshYjSjdzbEntity entity) {
        if (entity.getSjts()==0){
            return;
        }
        String sjpch = DateUtil.getNotContainsHMS(new Date());
        SjtgfJghshYjSjdzbEntity entity1 = jgReconciliationRepository.getByBmcAndSjpch(entity.getBmc(),sjpch);
        if (entity1!=null){
            entity1.setSjts(entity.getSjts()+entity1.getSjts());
            jgReconciliationRepository.save(entity1);
            return;
        }
        entity.setZdzt(1);
        //Integer lch = entity.getLch() == null ?1:entity.getLch();
        entity.setLch(1);
        entity.setFssj(DateUtil.getContainsHMS(new Date()));
        entity.setSjpch(sjpch);
        jgReconciliationRepository.save(entity);
    }
}
